<?php

namespace app\beautiful\model\mall;

use app\common\model\CommonModel;
use think\facade\Db;


class PinTuanGoodsSkuModel extends CommonModel{

    protected  $name = 'beautiful_pin_tuan_goods_sku';

    protected  $pk   = 'pin_tuan_goods_sku_id';

    public static function list($where,$order,$page=1,$limit=10,$field='*'){
        $query = Db::name('beautiful_pin_tuan_goods_sku')->alias('pgs')
            ->leftJoin('beautiful_goods_sku gs','gs.sku_id=pgs.sku_id')
            ->leftJoin('beautiful_goods_other_sku_detail sd','sd.other_sku_detail_id=gs.unit_id')
            ->where(['pgs.is_delete'=>0])
            ->when(isset($where['shop_id']),function ($query) use ($where){
                $query->where(['pgs.shop_id'=>$where['shop_id']]);
            })
            ->when(!empty($where['pin_tuan_goods_id']),function ($query) use ($where){
                $query->where(['pgs.pin_tuan_goods_id'=>$where['pin_tuan_goods_id']]);
            })
            ->field($field);
        $count = $query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        if(!empty($list)){
            foreach ($list as &$v){

            }
        }
        return compact('count','list');
    }

}

